'''
Created on Jan 25, 2013

@author: dexen
'''


import time
import random

import dexen 

from individual import Individual
from const import GEN_SIZE

pattern = [
[0,0,0,0,0,0,0,0,0,0],
[0,1,1,1,0,1,1,1,1,0],
[0,1,1,1,0,1,1,1,1,0],
[0,1,1,1,0,0,0,0,0,0],
[0,1,1,1,0,0,1,1,1,0],
[0,0,0,0,0,0,1,1,1,0],
[0,0,0,0,0,0,1,1,1,0],
[0,1,1,1,0,0,1,1,1,0],
[0,1,1,1,0,0,1,1,1,0],
[0,0,0,0,0,0,0,0,0,0],
]

class EvalSimilarityTask(dexen.BaseSlaveTask):
    def __init__(self):
        pass
    
    def __execute__(self, master_state, inds):
        for ind in inds:
            cnt = 0
            assert isinstance(ind, Individual)
            for row in range(10):
                for col in range(10):
                    a = ind.phenotype[row][col]
                    b = pattern[row][col]
                    if a == b:
                        cnt += 1
            ind.similarity = cnt
        return inds


    